﻿package frEngine.core
{
    import __AS3__.vec.*;
    import baseEngine.system.*;
    import flash.display3D.*;
    import flash.geom.*;
    import frEngine.shader.registType.*;

    public class DefaultSunLight extends FrLight3D
    {
        private var FcDirLightRegister:FcParam;
        private var FcDirColorRegister:FcParam;
        private var FcAmbientColorRegister:FcParam;
        private var dirLight:Vector.<Number>;

        public function DefaultSunLight()
        {
            this.dirLight = new Vector.<Number>(4, true);
            super("Default Sun Light", FrLight3D.DIRECTIONAL);
            this.infinite = true;
            this.FcDirLightRegister = Device3D.FcDirLightRegister;
            this.FcDirColorRegister = Device3D.FcDirColorRegister;
            this.FcAmbientColorRegister = Device3D.FcAmbientColorRegister;
            return;
        }// end function

        public function reinit(param1:Context3D) : void
        {
            param1.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, this.FcDirColorRegister.index, this.color, 1);
            param1.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, this.FcAmbientColorRegister.index, this.ambientColor, 1);
            param1.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, this.FcDirLightRegister.index, this.dirLight, 1);
            return;
        }// end function

        public function init() : void
        {
            this.setColor(10066329);
            this.setAmbientColor(10066329);
            this.setDirLight(new Vector3D(1, 1, -1));
            return;
        }// end function

        public function setDirLight(param1:Vector3D) : void
        {
            param1.normalize();
            this.dirLight[0] = param1.x;
            this.dirLight[1] = param1.y;
            this.dirLight[2] = param1.z;
            var _loc_2:* = Global3D.scene.context;
            _loc_2.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, this.FcDirLightRegister.index, this.dirLight, 1);
            return;
        }// end function

        public function setColor(param1:uint) : void
        {
            var _loc_2:* = 1 / 255;
            this.color[0] = ((param1 & 16711680) >> 16) * _loc_2;
            this.color[1] = ((param1 & 65280) >> 8) * _loc_2;
            this.color[2] = (param1 & 255) * _loc_2;
            var _loc_3:* = Global3D.scene.context;
            _loc_3.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, this.FcDirColorRegister.index, this.color, 1);
            return;
        }// end function

        public function setAmbientColor(param1:uint) : void
        {
            var _loc_2:* = 1 / 255;
            this.ambientColor[0] = ((param1 & 16711680) >> 16) * _loc_2;
            this.ambientColor[1] = ((param1 & 65280) >> 8) * _loc_2;
            this.ambientColor[2] = (param1 & 255) * _loc_2;
            var _loc_3:* = Global3D.scene.context;
            _loc_3.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, this.FcAmbientColorRegister.index, this.ambientColor, 1);
            return;
        }// end function

    }
}
